package _001_TwoSum;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class TwoSum03 {
	public static void main(String[] args) {
		int[] nums = {2, 7, 11, 15};
		int target = 9;
		System.out.println(Arrays.toString(new TwoSum03().twosum(nums, target)));
	}
	
	public int[] twosum(int[] nums, int target) {
		int len = nums.length;
		Map<Integer, Integer> map = new HashMap<>();
		for(int i = 0; i < len; i++) {
			if(map.containsKey(nums[i])) {
				return new int[] {map.get(nums[i]), i};
			}
			map.put(target - nums[i], i);
		}
		
		return null;
	}
}
